package com.xu.modules.controller;

import com.xu.common.domain.MyResult;
import com.xu.common.domain.PageQuery;
import com.xu.common.domain.TableDataInfo;
import com.xu.common.enums.ArticleNumTypeEnum;
import com.xu.modules.service.ArticleService;
import com.xu.modules.service.bo.ArticleBo;
import com.xu.modules.service.vo.ArticleVo;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 文章 前端控制器
 * </p>
 *
 * @author xu
 * @since 2022-07-26
 */
@RestController
@RequestMapping("/article")
@RequiredArgsConstructor
public class ArticleController {

    private final ArticleService articleService;

    @PostMapping("/add")
    public MyResult add(@RequestBody @Valid ArticleBo articleBo){
        articleService.add(articleBo);
        return MyResult.ok();
    }

    @GetMapping("/listPage")
    public TableDataInfo<ArticleVo> listPage(ArticleBo articleBo, PageQuery pageQuery){
        return articleService.listPage(articleBo,pageQuery);
    }

    @GetMapping("/detail/{articleId}")
    public MyResult detail(@PathVariable Long articleId){
        return MyResult.ok(articleService.detail(articleId));
    }

    @GetMapping("/good/{articleId}")
    public MyResult good(@PathVariable Long articleId){
        articleService.addArticleNum(articleId, ArticleNumTypeEnum.GOOD);
        return MyResult.ok();
    }
}
